package me.moscrop.RootCommand.listeners;

import me.moscrop.RootCommand.commands.Homes;
import org.bukkit.Effect;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

import me.moscrop.RootCommand.utilities.Chat;

public class RCPlayerListener extends PlayerListener {
	
	public void onPlayerBedEnter( PlayerBedEnterEvent event) {
		Player sender = event.getPlayer();
		Homes.setHome(sender);

		Chat.messageAll(sender, " is sleeping");		
	}

	public void onPlayerBedLeave( PlayerBedLeaveEvent event) {
		Player player = event.getPlayer();		
		Chat.messageAll(player, " is awake");
	}
	
	public void onPlayerRespawn( PlayerRespawnEvent event) {
		Homes.sendToHome(event);
	}
	
	public void onPlayerGameModeChangeEvent( PlayerGameModeChangeEvent event ) {
		
		
	}
	
	@Override
	public void onPlayerChat(final PlayerChatEvent event) {		
		event.setCancelled(true);	
		Chat.messageAll(event.getPlayer(), ": " + event.getMessage());
	}
	
	public void onPlayerTeleport(PlayerTeleportEvent event){
		Player player = event.getPlayer();
		
		player.playEffect(event.getFrom(), Effect.SMOKE, 4);
		player.playEffect(event.getTo(), Effect.SMOKE, 4);	
	}
}
